package cate.game.play.skill.passive.fairy;

import cate.game.play.config.PlayCfgArgs;
import cate.game.play.proce.action.ctx.ActionCtx;
import cate.game.play.proce.turn.AppendTurn;
import cate.game.play.skill.Skill;
import cate.game.play.skill.passive.common.立即复活PH;
import cate.game.play.skill.passive.hero.海神惊涛PH;

/**
 * 效果1：若第二回合仍未触发"海神惊涛"则释放1次"索命鱼叉"，
 * 效果2：4回合内死亡会以35%生命值再次复活，且本回合免疫1次技能伤害
 */
public class 鲱鱼罐头灵器PH extends 立即复活PH {


	private int 追加技能回合;
	private int 追加技能原型;

	private int 复活回合;
	private double 复活系数;
	private int 免疫buff;

	//追加技能回合=2&追加技能原型=？？
	//&复活回合=4&复活系数=3500&免疫buff=？？
	@Override
	public void parse(String code) {
		PlayCfgArgs args = new PlayCfgArgs(code);
		追加技能回合 = args.getInt("追加技能回合", 0);
		追加技能原型 = args.getInt("追加技能原型", 0);

		复活回合 = args.getInt("复活回合", 0);
		复活系数 = args.getWDouble("复活系数", 0d);
		免疫buff = args.getInt("免疫buff", 0);
	}

	private 海神惊涛PH 海神惊涛ph;

	@Override
	public void onFirstEnter(ActionCtx action) {
		海神惊涛ph = skill.owner.skill.getHandler(海神惊涛PH.class);
	}

	@Override
	public void onRoundEnd(ActionCtx action) {
		if (action.getRound().index != 追加技能回合) {
			return;
		}
		if (海神惊涛ph == null) {
			return;
		}
		if (!海神惊涛ph.isAddBuff()) {
			return;
		}
		Skill appendSkill = skill.owner.skill.getActiveSkillByProtoId(追加技能原型);
		if (appendSkill == null) {
			return;
		}
		action.getRound().addAppendTurn(new AppendTurn(skill.owner,appendSkill));
	}

	@Override
	protected double healValue() {
		return skill.owner.attr.total().hpTotal()*复活系数;
	}

	@Override
	protected int getResurrectMax() {
		return 1;
	}

	@Override
	protected boolean allowResurrect(ActionCtx action) {
		return action.getRound().index <= 复活回合;
	}

	@Override
	protected void onSuccess(ActionCtx action) {
		skill.owner.buff.tryAddByTid(action, 免疫buff);
	}
}
